import os
from docx import Document
from docx.shared import Inches
from datetime import datetime

# 创建文档
def create_report(output_dir):
    # 确保输出目录存在
    os.makedirs(output_dir, exist_ok=True)

    # 创建文档对象
    doc = Document()

    # 添加标题页
    # 标题页 - 空白段落调整位置
    for _ in range(5):
        doc.add_paragraph()

    # 主标题
    title = doc.add_heading('基站分析报告', 0)
    title.alignment = 1  # 居中对齐

    # 副标题
    subtitle = doc.add_heading('仪器设备使用记录分析', level=1)
    subtitle.alignment = 1

    # 添加空白段落
    doc.add_paragraph()
    doc.add_paragraph()

    # 添加生成日期
    date_str = datetime.now().strftime('%Y年%m月%d日')
    date_paragraph = doc.add_paragraph(f'生成日期: {date_str}')
    date_paragraph.alignment = 1

    # 保存文档
    report_path = os.path.join(output_dir, 'report.docx')
    doc.save(report_path)
    print(f'报告已成功创建: {report_path}')
    return report_path

if __name__ == '__main__':
    # 输出目录
    output_directory = '/Users/ricochen/program/base_station/test/输出/'
    create_report(output_directory)